﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;
using System.Dynamic;

namespace Eleanor.DAL
{
    public class AuthorshipDAL : DALBase
    {
        public List<dynamic> SelectAll()
        {
            var command = DefaultContext
                        .Sql("AuthorshipSelectALL")
                        .CommandType(DbCommandTypes.StoredProcedure);
            return command.QueryMany<dynamic>();
        }

        public dynamic CustomMapperUsingDynamic(dynamic row)
        {
            if (row == null)
            {
                return null;
            }
            dynamic authorship = new ExpandoObject();
            authorship.AuthorshipId = row.authorship_id;
            authorship.Value = row.value;
            authorship.CountOfPaint = row.count_of_paint;
            authorship.CreateDate = row.create_date;
            authorship.UpdateDate = row.update_date;
            return authorship;
        }


        public dynamic Select(string authorshipName)
        {
            const string sql = @"select * from authorship where value=@0";
            return CustomMapperUsingDynamic(DefaultContext.Sql(sql).Parameters(authorshipName).QuerySingle<dynamic>());
        }
    }
}
